//
//  YeeSettingVC.m
//  YeeShopProject
//
//  Created by CoderYee on 2017/3/9.
//  Copyright © 2017年 CoderYee. All rights reserved.
//

#import "YeeSettingVC.h"
#import "XRCommonOnlyButtontableCell.h"
#import "YeeCacheManger.h"
@interface YeeSettingVC ()
{
    NSString   *_cachestring;
    
}
@end

@implementation YeeSettingVC

- (void)viewDidLoad
{
    [super viewDidLoad];
}
-(void)addOwnViews
{
    [super addOwnViews];
    
}
-(void)configOwnViews
{
    [super configOwnViews];
    [self.view setBackgroundColor:xBackgroundColor];
    [self.tableView setBackgroundColor:xBackgroundColor];
    _cachestring=@"计算中...";
   // self.tableView.separatorColor=[UIColor clearColor];
    [self getCacheSize];
    
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 2;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return section==0?3:1;
    
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section==0)
    {
        UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:NSStringFromClass([UITableViewCell class])];
        if (cell==nil)
        {
            cell=[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:NSStringFromClass([ UITableViewCell class])];
        }
        cell.selectionStyle=UITableViewCellSelectionStyleNone;
        NSArray *titleArray=@[@"清除缓存",@"关于我们",@"联系平台"];
        cell.accessoryType=UITableViewCellAccessoryDisclosureIndicator;
        cell.textLabel.text=titleArray[indexPath.row];
        if (indexPath.row==0)
        {
            UILabel *rightLable=[[UILabel alloc] initWithFrame:CGRectMake(0, 13, kMainScreenWidth-120, 21)];
            rightLable.font=[UIFont Y_systemFontOfSize:12];
            rightLable.textColor=kGrayColor;
            rightLable.textAlignment=NSTextAlignmentRight;
            rightLable.text=_cachestring;
            
            cell.accessoryView=rightLable;
        }
       // cell.separatorInset=UIEdgeInsetsMake(0,kMainScreenWidth, 0, 0);
//        cell.separatorInset=UIEdgeInsetsMake(0, 0, 0, 0);
        return cell;
    }else
    {
        XRCommonOnlyButtontableCell *cell=[tableView dequeueReusableCellWithIdentifier:NSStringFromClass([UITableViewCell class])];
        if (cell==nil)
        {
            cell=[[XRCommonOnlyButtontableCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:NSStringFromClass([XRCommonOnlyButtontableCell class])];
            
        }
        cell.selectionStyle=UITableViewCellSelectionStyleNone;
        cell.layoutMargins=UIEdgeInsetsMake(0, kMainScreenWidth*0.5, 0, +kMainScreenWidth*0.5);;
        cell.separatorInset=UIEdgeInsetsMake(0, kMainScreenWidth*0.5, 0, +kMainScreenWidth*0.5);
        [cell setBackgroundColor:kClearColor];
        [cell.contentButton setTitle:@"退出登录" forState:UIControlStateNormal];
        cell.buttonBlock=^(void)
        {   //退出登录
            [self hostUserloginOut];
        };
        return cell;
    }
}
-(UIView*)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
    UIView *view=[[UIView alloc] init];
    return view;
}
-(UIView*)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    UIView *view=[[ UIView alloc] initWithFrame:CGRectMake(0, 0, kMainScreenWidth, 0.01)];
    return view;
}
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return 0.01;
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return section==0?0.01:70;
}
#pragma mark --单元格点击事件
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    
}
#pragma mark --退出登录
-(void)hostUserloginOut
{
    
    
}
#pragma mark --清除图片缓存
-(void)removeImageDisk
{

    [[YeeCacheManger manger] removeAllCache];
    
}
-(void)getCacheSize
{
    [[YeeCacheManger manger] getCacheSizeSuccessBlock:^(CGFloat cacheSize)
     {
        if (cacheSize < 1024)
        {
           _cachestring = @"0.0k";
        } else if (1024 > cacheSize && cacheSize < 1024 * 1024)
        {
           _cachestring = [NSString stringWithFormat:@"%0.2fk",cacheSize/1024.0];
        } else
        {
         _cachestring =[NSString stringWithFormat:@"%0.2fM",cacheSize/1024.0/1024.0];
        }
         [self.tableView reloadData];
    } failBlock:^(NSError *error)
    {
        
    }];
    
}
- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
}


@end
